#include "i2c_controller.h"

#define I2C_CTRL_NUM 10

static i2c_ctrl_p p_i2c_ctrls[I2C_CTRL_NUM];
static i2c_ctrl_p p_i2c_ctrl_selected;

int register_i2c_ctl(i2c_ctrl_p *p)
{
    int i;
    for (i = 0; i < I2C_CTRL_NUM; ++i) {
	if(!p_i2c_ctrls[i]){
	    p_i2c_ctrls[i] = p; 
	    return i; 
	}
    } 
    return -1;
}

int select_i2c_ctl(char* name)
{
    int i;
    for (i = 0; i < I2C_CTRL_NUM; ++i) {
	if(p_i2c_ctrls[i] && !strcmp(name,p_i2c_ctrls[i]->name)){
	    p_i2c_ctrl_selected = p_i2c_ctrls[i];
	    return i; 
	}
    } 

    return -1;
}

int i2c_transfer(i2c_msg_p msgs,int num)
{
    return p_i2c_ctrl_selected->master_xfer(msgs,num);
}

void init_i2c_ctl(void)
{
    s3c2440_i2c_ctrl_add();

    select_i2c_ctl("s3c2440");
    p_i2c_ctrl_selected->init();
}

